#!/usr/bin/env python2
# GoodFET Intel XScale
# 
# (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
# (C) 2010 Dave Huseby <dave at linuxprogrammer.org>
#
# This code is being rewritten and refactored.  You've been warned!

import sys;
import binascii;

from GoodFETXSCALE import GoodFETXSCALE
from intelhex import IntelHex

if len(sys.argv) == 1:
    print "Usage: %s verb [objects]\n" % sys.argv[0]
    print "%s reset" % sys.argv[0]
    print "%s chipid <index>" % sys.argv[0]
    sys.exit();

#Initailize FET and set baud rate
client = GoodFETXSCALE()
client.serInit()

#Connect to target
client.setup()
client.start()

if sys.argv[1] == "reset":
    client.reset_target()

if sys.argv[1] == "chipid":
    if len(sys.argv) < 3:
        print "missing argument"
        sys.exit()
    idx = int(sys.argv[2])
    id = client.get_device_id(idx)
    print "\tDevice %d ID: 0x%s" % (idx, hex(id)[2:].zfill(8).upper())

client.stop()
